<template>
  <header>
    <!-- 面包屑 -->
    <div class="l-content">
      <img
        src="../assets/images/name.png"
        style="margin: 14px 19px"
        alt="vprisk"
      />
    </div>
    <div class="appsClass" ref="appsClass">
      <i
        ref="appBtn"
        class="el-icon-s-grid"
        style="margin-right: 5px; width: 100px; height: 13px"
        @mousemove="appListEvent($event)"
        @click="appClick"
        ><span>应用分类</span></i
      >
      <div class="appList" ref="appList">
        <ul>
          <li
            v-for="(item, i) in appList"
            :key="i"
            :style="'background:' + item.color"
            v-show="moduleShow[item.moduleCode]"
            @click="showMenu(item.moduleCode, item.text)"
          >
            <div><i :class="item.icon"></i></div>
            <p>{{ item.text }}</p>
          </li>
        </ul>
      </div>
    </div>
    <!-- 主题中心  -->
    <el-popover placement="bottom" width="150" trigger="click" v-if="false">
      <div class="theme-center">
        <ul>
          <li @click="handleSelectedTheme(1)">
            <span class="org-rect"></span>
            <span>淡蓝</span>
          </li>
          <li @click="handleSelectedTheme(2)">
            <span class="blue-rect"></span>
            <span>钻石蓝</span>
          </li>
          <li @click="handleSelectedTheme(3)">
            <span class="black-rect"></span>
            <span>时尚黑</span>
          </li>
          <li @click="handleSelectedTheme(4)">
            <span class="white-rect"></span>
            <span>经典白</span>
          </li>
        </ul>
      </div>
      <el-link slot="reference" class="theme">
        <i class="skin gnxicon icon-self-skin"></i>主题
      </el-link>
    </el-popover>
    <div class="r-content">
      <div class="user_info">
        <ul>
          <li v-for="item in infoList" :key="item.icon" @click="item.function">
            <i :class="item.icon"></i>
            <el-badge :value="count" :max="99" :hidden="!item.badge || !count">
              <span style="height: 16px">{{ item.text }}</span>
            </el-badge>
          </li>
        </ul>

        <el-popover placement="bottom" width="150" trigger="click">
          <div class="pullDownBox">
            <div
              class="pullDownTop"
              v-for="item in pullDownData"
              :key="item.icon"
              @click="item.function"
            >
              <i style="font-size: 12px" :class="item.icon"></i>{{ item.text }}
            </div>
            <div @click="logOut" class="pullDownBottom">
              <i style="font-size: 12px" class="iconfont icon-tuichu"></i
              >退出登录
            </div>
          </div>
          <div style="width: 50px; margin-top: -3px" slot="reference">
            <i
              class="iconfont icon-top_gerenxinxi"
              style="font-size: 26px; color: #a7adba; cursor: pointer"
            ></i>
          </div>
        </el-popover>
      </div>
    </div>
    <el-dialog title="个人信息" :visible.sync="personalCenterDV" width="30%">
      <div>
        <persionInfo></persionInfo>
      </div>
    </el-dialog>
    <!-- 切换租户 -->
    <el-dialog title="切换工程" :visible.sync="visibleEngineer" width="30%">
      <EngineerTable
        ref="EngineerTable"
        @visibleEngineerCancel="visibleEngineerEventCancel"
        @visibleEngineerSave="visibleEngineerEventSave"
      ></EngineerTable>
    </el-dialog>
    <!-- 切换工程 -->
    <el-dialog
      title="license信息"
      :visible.sync="licenseMessageDV"
      width="500px"
    >
      <div>
        <div class="licenseMessageBox">
          <div class="licenseMessage">
            <span>license名称：</span>VP_ALM-V4.1.0
          </div>
          <div class="licenseMessage"><span>license类型：</span>类型一</div>
          <div class="licenseMessage"><span>工程状态：</span>多工程</div>
          <div class="licenseMessage"><span>开始日期：</span>2020-10-20</div>
          <div class="licenseMessage"><span>结束日期：</span>2021-10-20</div>
          <div class="licenseMessage">
            <span>剩余期限：</span>
            <span style="color: rgba(229, 126, 84, 1)">423天</span>
          </div>
          <div class="licenseMessage">
            <span>到期提醒设置：</span>
            <span style="color: rgba(229, 126, 84, 1)"
              >到期前30天开始提醒，提醒间隔3天</span
            >
          </div>
          <div class="licenseMessageBtn">
            <div>
              <el-button @click="switchFunction = false">导入license</el-button>
              <el-button @click="switchFunction = true">设置到期提醒</el-button>
            </div>
          </div>
        </div>
        <div v-if="!switchFunction">
          <div class="licenseMessageFile">
            <div>选择license文件：<span>选择文件</span></div>
          </div>
          <div class="licenseMessageBtn">
            <div>
              <el-button @click="licenseMessageDV = false">导 入</el-button>
              <el-button @click="licenseMessageDV = false">取 消</el-button>
            </div>
          </div>
        </div>
        <div v-if="switchFunction">
          <div class="licenseMessageFileForm">
            <el-form
              :model="licenseForm"
              style="width: 200px"
              ref="licenseForm"
              label-width="90px"
            >
              <el-form-item label="到期提醒：" prop="expirationReminder">
                <el-select v-model="value" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="提醒间隔：" prop="remindInterval">
                <el-select v-model="value" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </div>
          <div class="licenseMessageBtn">
            <div>
              <el-button @click="licenseMessageDV = false">确 定</el-button>
              <el-button @click="licenseMessageDV = false">取 消</el-button>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      title="修改密码"
      :visible.sync="changePasswordDV"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="isFirstLogin === false"
      width="514px"
    >
      <el-form
        :model="changePasswordForm"
        ref="changePasswordForm"
        label-width="97px"
        label-position="left"
        :rules="changePasswordFormRules"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="原密码：" prop="originalPassword">
              <el-input
                type="password"
                v-model="changePasswordForm.originalPassword"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="新密码：" prop="newPassword">
              <el-input
                type="password"
                v-model="changePasswordForm.newPassword"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="确认新密码：" prop="affirmNewPassword">
              <el-input
                type="password"
                v-model="changePasswordForm.affirmNewPassword"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="changePasswordConfirm">确 定</el-button>
        <el-button @click="changePasswordCancel" v-if="!isFirstLogin"
          >取 消</el-button
        >
        <el-button @click="logOut" v-if="isFirstLogin">退出</el-button>
      </div>
    </el-dialog>
    <web-socket ref="websocket" v-show="false"></web-socket>
  </header>
</template>

<script>
import { authentication } from "@/api/index";
import { mapState } from "vuex";
import { systemManage } from "@/api/index";
import { listToTree } from "@/lib/util";
import webSocket from "./webSocket/WebSocket";
import EngineerTable from "./EngineerTable";
import persionInfo from "../views/SystemMange/personInfo";
import sm4 from "@/lib/gmsm4/index";
// console.log(persionInfo, "persionInfo");
export default {
  components: { webSocket, persionInfo, EngineerTable },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.changePasswordForm.affirmNewPassword !== "") {
          this.$refs.changePasswordForm.validateField("affirmNewPassword");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.changePasswordForm.newPassword) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      isAdmin: false,
      userName: "",
      notContainsUsername: false,
      hisPwd: "", // 历史密码密文串
      moduleList: [],
      visibleEngineer: false, // 工程切换弹窗
      key: "40ca11f573cce61cc28e19998d5bb1c8",
      iv: "31313131313131313131313131313131",
      infoListPersonal: [],
      isFirstLogin: false,
      infoList: [
        {
          icon: "iconfont icon-daibantongzhi",
          text: "代办通知",
          function: () => {
            this.numFunc();
          },
          badge: true
        },
        {
          icon: "iconfont icon-gongchengqiehuan",
          // text: "租户切换",
          text: "工程切换",
          function: () => {
            if(!this.isAdmin){
              this.visibleEngineer = true;
               this.$nextTick(()=>{
               this.$refs.EngineerTable.projectQueryForPage();
            })
            }else{
              return this.$message.warning('该用户为系统管理员')
            }
           
          }
        }
      ],
      appList: [
        {
          text: "系统管理",
          color: "linear-gradient(160deg, #F2BC7C 0%, #F1882E 100%)",
          icon: "iconfont icon-xitongguanli",
          moduleCode: "SYS"
        },
        {
          text: "公共管理",
          color: "linear-gradient(341deg, #73C5B3 0%, #97DACB 100%)",
          icon: "iconfont icon-gonggongguanli",
          moduleCode: "CPM"
        },
        {
          text: "业务预算管理",
          color: "linear-gradient(145deg, #ECD36A 0%, #D7B047 100%)",
          icon: "iconfont icon-yewuyusuanguanli",
          moduleCode: "IES"
        },
        {
          text: "资产负债管理",
          color: "linear-gradient(154deg, #E79D9D 0%, #CC6868 100%)",
          icon: "iconfont icon-zichanfuzhaiguanli",
          moduleCode: "ALM"
        },
        {
          text: "资金头寸管理",
          color: "linear-gradient(161deg, #A0B4EC 0%, #7699CB 100%)",
          icon: "iconfont icon-zijintoucunguanli",
          moduleCode: "LPM"
        },
        {
          text: "资金转移定价",
          color: "linear-gradient(146deg, #A1DDAC 0%, #6CB678 100%)",
          icon: "iconfont icon-zijinzhuanyidingjia",
          moduleCode: "FTP"
        },
        {
          text: "成本分摊管理",
          color: "linear-gradient(137deg, #90D3CA 0%, #62AA9F 100%)",
          icon: "iconfont icon-chengbenfentanguanli",
          moduleCode: "CA"
        },
        {
          text: "报表分析",
          color: "linear-gradient(157deg, #B09EC7 0%, #7D5FA6 100%)",
          icon: "iconfont icon-baobiaofenxi",
          moduleCode: "RI"
        },

        {
          text: "经济资本计量",
          color: "linear-gradient(142deg, #E7D39E 0%, #BB9D5B 100%)",
          icon: "iconfont icon-jingjizibenjiliang",
          moduleCode: "ECM"
        },
        {
          text: "数据集市",
          color: "linear-gradient(142deg, #FFB58C 0%, #D68356 100%)",
          icon: "iconfont icon-shujujishi",
          moduleCode: "DM"
        },
        {
          text: "客户关系定价",
          color: "linear-gradient(157deg, #D9E1FE 0%, #9FA8D7 100%)",
          icon: "iconfont icon-huaban",
          moduleCode: "RPM"
        },
        {
          text: "数据补录",
          color: "linear-gradient(157deg, #D9E1FE 0%, #9FA8D7 100%)",
          icon: "iconfont icon-baobiaofenxi",
          moduleCode: "META"
        },
        {
          text: "工作流",
          color: "linear-gradient(146deg, #A1DDAC 0%, #6CB678 100%)",
          icon: "iconfont icon-shujujishi",
          moduleCode: "BPM"
        }
      ],
      moduleShow: {
        SYS: false,
        ALM: false,
        BPM: false,
        CA: false,
        CPM: false,
        DMS: false,
        ETL: false,
        FTP: false,
        IES: false,
        META: false,
        ORION: false,
        RI: false,
        RPM: false,
        DM: false,
        ECM: false,
        LPM: false
      },
      userInfoData: null,
      pullDownData: [
        {
          icon: "iconfont icon-yonghuguanli",
          text: "个人中心",
          function: this.personalCenterBtn
        },

        {
          icon: "iconfont icon-mimapeizhi",
          text: "修改密码",
          function: this.changePasswordBtn
        },
        {
          icon: "iconfont icon-licensexinxi1",
          text: "license信息",
          function: this.licenseMessageBtn
        }
      ],
      personalCenterDV: false,
      licenseMessageDV: false,
      changePasswordDV: false,
      changePasswordForm: {
        originalPassword: "",
        newPassword: "",
        affirmNewPassword: ""
      },
      changePasswordFormRules: {
        originalPassword: [
          {
            required: true,
            message: "请输入原密码",
            trigger: "blur"
          }
        ],
        newPassword: [
          {
            required: true,
            validator: validatePass,
            trigger: "blur"
          }
        ],
        affirmNewPassword: [
          {
            required: true,
            validator: validatePass2,
            trigger: "blur"
          }
        ]
      },
      switchFunction: true,
      licenseForm: {
        expirationReminder: "",
        remindInterval: ""
      },
      options: [
        {
          value: "1",
          label: "15天"
        },
        {
          value: "2",
          label: "30天"
        },
        {
          value: "3",
          label: "45天"
        }
      ],
      value: ""
    };
  },
  computed: {
    ...mapState({
      current: state => state.tab.currentMenu,
      count: state => state.user.message.count
    })
  },
  created() {
    this.getUserInfo();
    this.init();
    // this.getMenus()
  },
  mounted() {
    // 点击应用列表外，隐藏appList
      document.body.onclick = e => {
        var e = e || window.event;
        var edom = e.target;
        let aDom = this.$refs.appsClass;
        if(!aDom)return ;
        if (!aDom.contains(edom)) {
          let bDom = this.$refs.appList;
          bDom.style.opacity = 0;
          bDom.style.height = 0;
        }
      };
  },
  methods: {
    // 密码策略获取
    getPasswordRlue(data) {
      systemManage.passwardValidRule(data).then((res) => {
        let list = res.data.rules;
        // 前n次旧密码
        if (this.saveFlg != 1) {
          this.hisPwd = res.data.str_not_his_numbs.rule;
        }
        let passwordRule = [
           {
            required: true,
            validator: this.validFirtPassword,
            trigger: "blur"
          }
        ];
        for (let i = 0; i < list.length; i++) {
          let obj = {
            pattern: eval("/" + list[i].rule + "/"),
            message: list[i].msg,
            trigger: "blur",
          };
          passwordRule.push(obj);
        }
        this.changePasswordFormRules.newPassword = passwordRule;
      });
    },
      // 密码校验是否设置了不包含用户名
    isContainsUsername(rule, value, callback) {
      systemManage.findDefPasswordRule().then((res) => {
        if (res.code == 200) {
          this.notContainsUsername = res.data.notContainsUsername == "1";
        }
      });
    },
     validFirtPassword(rule, value, callback) {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.changePasswordForm.affirmNewPassword !== "") {
          this.$refs.changePasswordForm.validateField("affirmNewPassword");
        }
         if (
        this.changePasswordForm.newPassword != "password" &&
        this.userName.length > 0 &&
        this.notContainsUsername === true &&
        this.changePasswordForm.newPassword.indexOf(this.userName) != -1
      ) {
        callback(new Error("密码中不能包含用户名"));
        return;
      }
        callback();
      }
    },

    // 点击应用分类事件处理
    appClick() {
      let dom = this.$refs.appList;
      if (dom.style.opacity != 1) {
        dom.style.opacity = 1;
        dom.style.height = this.getAppHeight();
        // dom.style.height = "auto";
      } else {
        dom.style.opacity = 0;
        dom.style.height = 0;
      }
    },
    // 根据模块数获取appList高度(auto不支持渐变动画)
    getAppHeight() {
      let n = 0;
      for (const key in this.moduleShow) {
        if (this.moduleShow[key]) {
          n = n + 1;
        }
      }
      if (!n) return 0;
      let h = n / 4 + "";
      if (h.length == 1) return h * 100 + 12 + "px";
      else return (h.substring(0, 1) * 1 + 1) * 100 + 12 + "px";
    },
    init() {
      this.projectQueryForPage();
    },
    // 获取所有工程
    projectQueryForPage() {
       if (!sessionStorage.getItem("projectId")) {
        systemManage.getMgrProjects().then(res => {
          if (res.code == 200) {
            if (res.datas.isAdmin == true) {
              this.isAdmin = true
              console.log('系统管理员')
              this.getIsAdminEnableModules();
            } else {
               this.isAdmin = false
               if (res.datas.data.length == 0) {
              return this.$message.error("该用户未授权工程,请联系管理员");
            } else {
              for (let i = 0; i < res.datas.data.length; i++) {
                // 判断是否有默认值
                if (res.datas.data[i].isDefault == "1") {
                  sessionStorage.setItem("projectId", res.datas.data[i].projectId);
                  sessionStorage.setItem("projectName", res.datas.data[i].projectId);
                  this.getEnableModules();
                  break;
                }
              }
            }
            }
          } else {
            this.$message.error(res.message);
          }
        });
      }
    },

    appListEvent(val) {
      if (sessionStorage.getItem("moduleShow")) {
        this.moduleShow = JSON.parse(sessionStorage.getItem("moduleShow"));
        console.log(this.moduleShow, " this.moduleShow");
      }
      var i = 0;
      for (const key in this.moduleShow) {
        if (this.moduleShow[key] == false) {
          i = i + 0;
        } else {
          i = i + 1;
        }
      }
      if (i == 0) {
        this.$message.warning("未找到相应模块，请在右侧选择工程");
      }
    },
    visibleEngineerEventCancel(val) {
      this.visibleEngineer = val;
    },
    visibleEngineerEventSave(val) {
      this.visibleEngineer = val;
      let data = this.$refs.EngineerTable.$refs.multipleTable.selection;
      sessionStorage.setItem("projectId", data[0].projectId);
      sessionStorage.setItem("projectName", data[0].projectName);
      this.getEnableModules();
    },
    numFunc() {
      this.$store.commit("toMessagePage");
      this.$router.push({ name: "message" });
    },
    getUserInfo() {
      systemManage
        .getCurrentUserInfo()
        .then(res => {
          if (res.code == 200) {
            this.userInfoData = res.data;
            this.userName = res.data.userName
            this.$store.commit("setUserInfo", res.data);
            this.queryPasswordRule();
          }
        })
        .catch(err => {
          console.log(err,'getUserInfo报错');
        });
    },
    queryPasswordRule() {
      systemManage.findDefPasswordRule().then(res => {
        if (res.code == 200) {
          if (res.data.atFirstLogin == "1") {
            this.isFirstLogin =
              this.userInfoData.isFirstLogin == "1" ? true : false;
            this.changePasswordDV = this.isFirstLogin;
          }
        }
      });
    },
    logOut() {
      // 调用登出方法
      authentication.removeToken().then(res=>{
        if(res.code == 200 && res.success == true) {
          sessionStorage.removeItem("projectId")
          this.$store.dispatch("logOut");
        } else{
          this.$messsage.error(res.message || '失败')
        }
      })
    },
    handleSelectedTheme(number) {
      document.body.className = "theme-" + number;
    },
    // 获取用户可见模块

    getEnableModules() {
      if(this.isAdmin){
        var data = {
        projectId: ""
      }
      } else{
         var data = {
        projectId: sessionStorage.getItem("projectId"),
      };
      }
      // 调用根据工程id切换工程
      // 
      systemManage.changeProject(data).then((res)=>{
        if(res.code == 200 && res.success == true) {
          this.getIsAdminEnableModules()
        }else{
          this.$message.error(res.message || '失败')
        }
      }) 
    },

    getIsAdminEnableModules(){
      if(this.isAdmin){
        var data = {
        projectId: ""
      }
      } else{
         var data = {
        projectId: sessionStorage.getItem("projectId"),
      };
      }
        systemManage.queryModulesWithProjectId(data).then(res => {
        if (res.code == 200) {
          for (const key in this.moduleShow) {
            this.moduleShow[key] = false;
          }
          if (res.datas.length == 0) {
            sessionStorage.setItem("moduleShow", []);
            this.$store.commit("setUserMenu", []);
            sessionStorage.setItem("userMenuList", '');
            // 先清除侧边栏菜单，以免用户二次登录
            this.$store.commit("clearMenu");
            this.$store.commit("setMenu", []);
            this.$store.commit("addMenu", this.$router);
            let firstmenu = {
              path: "/",
              name: "home",
              label: "欢迎页面",
              icon: "home"
            };
            this.$router.push({ name: "home" });
            this.$store.commit("selectMenu", firstmenu);
            return this.$message.error("未授权,未找到对应模块");
          } else {
            this.moduleList = res.datas;
            // 只渲染可见模块
            res.datas.map(v => {
              this.moduleShow[v.moduleCode] = true;
            });
            sessionStorage.removeItem("moduleShow");
            let moduleShowStr = JSON.stringify(this.moduleShow);
            sessionStorage.setItem("moduleShow", [moduleShowStr]),
              this.getMenus();
              // 获取到模块后直接显示模块apps
              this.appClick();
          }
        } else {
          this.$messsage.error(res.message || '失败')
        }
      });
    },
    //
    // 获取菜单
    getMenus() {
      systemManage.queryUserMenu().then(res => {
        if (res.code == 200) {
          let menuList = [];
          let dataList = res.datas.sort((x, y) => {
            return x.displayOrder - y.displayOrder;
          });
          dataList.map(v => {
            let pathArr = v.menuUrl ? v.menuUrl.split("/") : [""];
            let path = pathArr[pathArr.length - 1];
            let item = {
              menuId: v.menuId,
              // path: path ? '/' + path : '', // 路由即/+文件名
              // 避免文件名重复带来的路由重复，菜单路由采用实际页面文件路径，读取页面仍使用url
              path: path ? "/" + v.menuUrl : "",
              name: path,
              url: v.menuUrl,
              label: v.menuName,
              icon: v.iconName,
              pId: v.parentMenuId,
              pName: v.parentMenuName,
              openFlag: v.openFlag,
              menuType: v.menuType,
              moduleCode: v.moduleCode
            };
            menuList.push(item);
          });
          // 保存所有的菜单list
          this.$store.commit("setUserMenu", menuList);
          sessionStorage.setItem("userMenuList", JSON.stringify(menuList));

          // 后台返回的菜单数据，需要处理成可用数据
          //  默认显示系统管理,如果没有授权系统管理则展示第一个模块的菜单
          let MC = "";
          let MCName = "";
          if (
            this.moduleList.findIndex(item => item.moduleCode == "SYS") == -1
          ) {
            MC = this.moduleList[0].moduleCode;
            MCName = this.moduleList[0].moduleName;
          } else {
            MC = "SYS";
            MCName = "系统管理";
          }
          let menu = this.getMenuByModuleCode(MC, menuList);
          // 向后台发送模块切换信息
          // let data = {
          //   moduleCode: MC,
          //   moduleName: MCName
          // };
          // systemManage.changeModule(data).then(res => {
          //   if (res.code == 200) {
          //     console.log(res);
          //   }
          // });
          //
          // 先清除侧边栏菜单，以免用户二次登录
          this.$store.commit("clearMenu");
          // 设置侧边栏菜单
          this.$store.commit("setMenu", menu);
          this.$store.commit("addMenu", this.$router);

          let firstmenu = {
            path: "/",
            name: "home",
            label: "欢迎页面",
            icon: "home"
          };
          this.$router.push({ name: "home" });
          this.$store.commit("selectMenu", firstmenu);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 根据模块code 获取该模块下菜单并转化为tree
    getMenuByModuleCode(moduleCode, list) {
      let currentMenuList = [];
      for (let i = 0; i < list.length; i++) {
        if (list[i].moduleCode == moduleCode) {
          currentMenuList.push(list[i]);
        }
      }
      let menuTree = listToTree("menuId", "pId", currentMenuList);
      if (menuTree.length == 0) {
        return [];
      } else {
        return menuTree[0].children;
      }
    },

    //
    // 获取对应模块菜单
    showMenu(code, name) {
      // 向后台发送模块切换信息
      // let data = {
      //   moduleCode: code,
      //   moduleName: name
      // };
      // systemManage.changeModule(data).then(res => {
      //   if (res.code == 200) {
      //     console.log(res);
      //   }
      // });
      let json = sessionStorage.getItem("userMenuList");
      if (!json) {
        return this.$message.error("未获取到该用户菜单信息，请重新登陆。");
      }
      let list = JSON.parse(json);
      let currentMenuList = [];
      for (let i = 0; i < list.length; i++) {
        if (list[i].moduleCode == code) {
          currentMenuList.push(list[i]);
        }
      }
      if (currentMenuList.length == 0) {
        return this.$message.warning("该角色" + name + "模块下未配置菜单");
      }
      let menu = this.getMenuByModuleCode(code, list, name);

      // 先清除侧边栏菜单
      this.$store.commit("clearMenu");
      // 设置侧边栏菜单
      this.$store.commit("setMenu", menu);
      this.$store.commit("addMenu", this.$router);
      let firstmenu = {
        path: "/",
        name: "home",
        label: "欢迎页面",
        icon: "home"
      };
      this.$router.push({ name: "home" });
      this.$store.commit("selectMenu", firstmenu);

      this.$message.success("切换成功！");
    },
    // 根据模块code 获取该模块下菜单并转化为tree
    getMenuByModuleCode(moduleCode, list, name) {
      let currentMenuList = [];
      for (let i = 0; i < list.length; i++) {
        if (list[i].moduleCode == moduleCode) {
          currentMenuList.push(list[i]);
        }
      }
      let menuTree = listToTree("menuId", "pId", currentMenuList);
      console.log("当前菜单", menuTree);
      return menuTree[0].children;
    },
    //个人信息
    personalCenterBtn() {
      this.personalCenterDV = true;
    },
    //license信息
    licenseMessageBtn() {
      return this.$message.warning("此功能未开放");
      this.licenseMessageDV = true;
    },
    //修改密码
    changePasswordBtn() {
      this.getPasswordRlue({});
      this.isContainsUsername();
      (this.changePasswordForm = {
        originalPassword: "",
        newPassword: "",
        affirmNewPassword: ""
      }),
      (this.changePasswordDV = true);
      this.$nextTick(() => {
        this.$refs.changePasswordForm.clearValidate();
      });
    },
    //确认
    changePasswordConfirm() {
      this.$refs.changePasswordForm.validate(valid => {
        if (valid) {
          //加密
          let data = {
            hisPwd: sm4.encryptWithECB(
              this.key,
              this.changePasswordForm.originalPassword
            ),
            password: sm4.encryptWithECB(
              this.key,
              this.changePasswordForm.newPassword
            )
          };
          systemManage.comparePassword(data).then(res => {
            if (res.code == 200) {
              systemManage.updatePassword(data).then(res => {
                if (res.code == 200) {
                  this.changePasswordDV = false;
                  if (this.isFirstLogin) {
                    this.$alert("请返回登陆页面重新登陆", "修改密码成功", {
                      confirmButtonText: "确定",
                      callback: action => {
                        this.$router.push({ name: "login" });
                      }
                    });
                  } else {
                    this.$message.success(res.message);
                  }
                } else {
                  this.$message.error(res.message);
                }
              });
            } else {
              this.$message.error(res.message);
            }
          });
        } else {
          console.log("错误");
          return false;
        }
      });
    },
    //取消
    changePasswordCancel() {
      this.$refs.changePasswordForm.resetFields();
      this.changePasswordDV = false;
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-badge__content.is-fixed {
  top: 11px;
  right: 5px;
}
header {
  height: 100%;
  background: white;
  box-shadow: 0px 2px 4px 0px #e4e8eb;
}
.l-content {
  float: left;
  h3 {
    margin-top: 14px;
    margin-left: 19px;
    width: 186px;
    height: 22px;
    font-size: 22px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 500;
    color: #40506f;
    line-height: 22px;
  }
  p {
    margin-top: 4px;
    width: 380px;
    height: 4px;
    margin-left: 19px;
    line-height: 4px;
    font-size: 4px;
    font-family: DINAlternate-Bold, DINAlternate;
    font-weight: bold;
    color: #a6b1c7;
  }
}

.appsClass {
  float: left;
  margin: 24px 21px;
  width: 88px;
  height: 17px;
  text-align: left;
  font-size: 14px;
  color: #a7adba;
  .el-icon-s-grid {
    cursor: pointer;
    font-size: 16px;
    position: relative;
    span {
      position: absolute;
      height: 16px;
      font-size: 14px;
      top: 1px;
      left: 17px;
    }
  }
}
.appList {
  transition: all 0.7s;
  position: absolute;
  z-index: 999;
  padding-right: 10px;
  padding-bottom: 10px;
  opacity: 0;
  max-width: 412px;
  height: 0;
  top: 50px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0px 2px 4px 0px #d4d8e3;
  border: 1px solid #e0e4ec;
  ul {
    li:hover {
      opacity: 0.8;
    }
    li {
      display: inline-block;
      overflow: hidden;
      margin-top: 10px;
      margin-left: 10px;
      width: 90px;
      height: 90px;
      border-radius: 4px;
      cursor: pointer;
      div {
        height: 62px;
        text-align: center;
        padding-top: 14px;
        .iconfont {
          width: 33px;
          height: 32px;
          font-size: 32px !important;
          color: #fff;
        }
      }
      p {
        text-align: center;
        height: 28px;
        font-size: 12px;
        font-family: PingFang-SC-Medium, PingFang-SC;
        font-weight: 500;
        color: #ffffff;
        line-height: 28px;
        background-color: rgba(0, 0, 0, 0.2);
      }
    }
  }
}
.user_info {
  float: left;
  height: 50px;
  margin-top: 6px;
  display: flex;
  line-height: 50px;
  ul {
    display: flex;
    li {
      margin-right: 35px;
      font-size: 12px;
      color: #a7adba;
      cursor: pointer;
    }
  }
}
.r-content {
  float: right;
  height: 100%;
  .user {
    vertical-align: middle;
    height: 40px;
    margin: 10px 19px;
    background-size: 100%;
    border-radius: 50%;
  }
}
</style>
<style lang="scss">
.el-breadcrumb__item {
  .el-breadcrumb__inner {
    color: #666;
    font-weight: normal;
  }
  &:last-child {
    .el-breadcrumb__inner {
      color: rgb(27, 26, 26);
    }
  }
}
.icon-top_licensexiaoxi {
  font-size: 12px;
}
</style>
<!-- 头部样式 -->
<style lang="scss" scoped>
.pullDownBox {
  background: rgba(76, 86, 108, 1);
  color: #fff;
  margin: -14px;
  border-radius: 4px;
  .pullDownTop {
    height: 30px;
    font-size: 12px;
    padding: 14px;
    margin-left: 10px;
    cursor: pointer;
  }
  .pullDownBottom {
    height: 42px;
    font-size: 12px;
    padding: 10px 0px 0px 25px;
    margin-top: 16px;
    border-top: 1px solid rgba(105, 115, 136, 1);
    cursor: pointer;
  }
}
.personalCenterBox {
  height: 210px;
  padding: 10px;
  .personalCenterTit {
    width: 80px;
    height: 18px;
    font-size: 12px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #232e46;
    line-height: 18px;
    margin-bottom: 11px;
  }
  .personalCenter {
    margin-bottom: 10px;
    width: 400px;
    height: 18px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #242f47;
    line-height: 18px;
  }
}
.licenseMessageBox {
  height: 410px;
  padding: 10px;

  .licenseMessage {
    margin-bottom: 10px;
    width: 400px;
    height: 18px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #242f47;
    line-height: 18px;
    span {
      font-weight: 900;
    }
  }
}
.licenseMessageFile {
  position: absolute;
  top: 340px;
  left: 0px;
  width: 500px;
  height: 120px;
  border-top: 1px solid rgba(238, 239, 240, 1);
  border-bottom: 1px solid rgba(238, 239, 240, 1);
  font-size: 14px;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  span {
    font-size: 12px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #db6943;
    line-height: 17px;
    text-decoration: underline;
    cursor: pointer;
  }
}
.licenseMessageFileForm {
  padding: 10px;
  position: absolute;
  top: 340px;
  left: 0px;
  width: 500px;
  height: 120px;
  border-top: 1px solid rgba(238, 239, 240, 1);
  border-bottom: 1px solid rgba(238, 239, 240, 1);
  font-size: 14px;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  span {
    font-size: 12px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #db6943;
    line-height: 17px;
    text-decoration: underline;
    cursor: pointer;
  }
}

.licenseMessageBtn {
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.changePasswordBox {
  height: 100px;
  padding: 10px;
}
.changePasswordBtn {
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
